<html>
<head>
<title>Example eID picture</title>
<script type="text/javascript" src="..\src\be_belgium_eid.js"></script>
<script type="text/javascript" src="..\src\base64.js"></script>
<script type="text/javascript" language="javascript">

var cardReader = new be.belgium.eid.CardReader();

function noCardPresentHandler() {
	window.alert("No card present!");
}
cardReader.setNoCardPresentHandler(noCardPresentHandler);

function noReaderDetectedHandler() {
	window.alert("No reader detected!");
}
cardReader.setNoReaderDetectedHandler(noReaderDetectedHandler);

function appletNotFoundHandler() {
	window.alert("Applet not found!");
}
cardReader.setAppletNotFoundHandler(appletNotFoundHandler);

function appletExceptionHandler(e) {
	window.alert("Error reading card!\r\nException: " + e + "\r\nPlease try again.");
}
cardReader.setAppletExceptionHandler(appletExceptionHandler);

function clearPicture() {
	document.getElementById("encoded_picture").src = "data:image/jpeg;base64,";
}

function readCard() {
	clearPicture();

	document.getElementById("content").value = "Please wait ...";
	var card = cardReader.read();
	if (card != null) {
		var content = card.toString();
		if (typeof(base64) != "undefined") {
			var encodedPicture = base64.encode(card.getPicture(), false, false);
			document.getElementById("encoded_picture").src = "data:image/jpeg;base64," + encodedPicture;
			content += "\r\n\r\n" + encodedPicture;
		} else {
			window.alert("base64 object not defined");
			content += "\r\n\r\n" + "base64 object not defined";
		}
		document.getElementById("content").value = content;
	} else {
		document.getElementById("content").value = "No card returned.";
	}
}

</script>
</head>
<body>
<script type="text/javascript" language="javascript">

//----------------
// give the following variables:
// subdir: the subdirectory where the applet jar file resides
// jnlpPath: the path to the jnlp file
// ex: subdir="appletDir";
//     jnlpPath=subdir;
//----------------
var subdir="";
var jnlpPath=subdir;

//----------------
// - get the href of this page
// - strip off the name of this page
//----------------
var myloc 	 = window.location.href;
var locarray = myloc.split("/");
delete locarray[(locarray.length-1)];
var url = locarray.join("/");

	document.writeln('<applet code="org.jdesktop.applet.util.JNLPAppletLauncher"');
    document.writeln('codebase = "' + url + subdir + '"');
    document.writeln('width  ="140"');
    document.writeln('height ="200"');
    document.writeln('name   = "BEIDAppletLauncher"');
	document.writeln('id   = "BEIDAppletLauncher"'); // add id attribute !!!
    document.writeln('archive="applet-launcher.jar,beid35libJava.jar,BEID_Applet.jar">');

	document.writeln('<param name="codebase_lookup" value="false">');
	document.writeln('<param name="subapplet.classname" value="be.belgium.beid.BEID_Applet">');
	document.writeln('<param name="progressbar" value="true">');
	document.writeln('<param name="jnlpNumExtensions" value="1">');
	document.writeln('<param name="jnlpExtension1" value= "' + url + jnlpPath + '/beid.jnlp">');

	document.writeln('<param name="debug" value="false"/>');
	document.writeln('<param name="Reader" value=""/>');
	document.writeln('<param name="OCSP" value="-1"/>');
	document.writeln('<param name="CRL" value="-1"/>');
	document.writeln('<param name="jnlp_href" value="' + url + jnlpPath + '/beid_java_plugin.jnlp" />');
	document.writeln('</applet>');

</script>
<br>
<br>
<input type="button" onclick="javascript:readCard()" value="Read Card" title="Read Card"/>
<br>
<br>
Card content:<br>
<textarea id="content" cols=80 rows=20 wrap="virtual">&nbsp;</textarea>
<img src="" id="encoded_picture" width=140 height=200><br>
<br>
<u>Remarks:</u><br>
1. The Base64 encoding works in Firefox and Opera without a problem.<br>
But in Internet Explorer, the Base64 encoding will only work if JRE 6 Update 10 (Java Runtime Environment 1.6.0_10) or higher is installed<br> 
and if the Next-Generation Java Plug-in is enabled (this is the default setting) in the Java Control Panel.<br>
<br>
2. The encoded image (image at the right of the textarea) will only be shown in Firefox and Opera.<br>
The Base64 encoded picture string will be shown in the textarea in every browser.<br>
<br>
3. The code for base64.js can be downloaded at <a href="http://hellerim.net/base64_src.php">http://hellerim.net/base64_src.php</a><br>
Small modifications needs to be done. Please keep the copyright statement intact.<br>
Put the following code in comments:<br>
<pre>
/*
try { 
  if (system.utility.base64 == null) {
    throw new Error('');
  };
} catch(e) { // don't install twice
  // dependencies
  try {
    eval('core');
  } catch(e) {
    throw new Error('base64: class \'core\' not installed');
  }
*/
</pre>
and at the bottom line:<br>
<pre>
/*
core.installClass(base64);

} // end catch
*/
</pre>
<br>
<br>
</body>
</html>